<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目合作信息</title>
<link rel="stylesheet" type="text/css" href="/css/front/conn.css"/>
<link rel="stylesheet" type="text/css" href="/css/front/list7.css"/>
    <script src="/js/plugs/jquery.js"></script>
    <script src="/js/admins/base.js"></script>
    <script src="/js/plugs/validate.js"></script>

    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>

    <style>
	.del {
		background: #d9534f !important;
		color: #fff !important;
		border: 1px solid #d9534f !important;
	}
	.cor h6 {
       color: #999;
       font-size: 13px;
    }
	
	.cor button.btn {
		margin:0 auto !important;
}

    </style>

</head>

<body >
<!-- 头部导航开始 -->
{# include file="$tpl_root_path/front/public/_header.html" #}
<!-- 头部导航结束 -->




<!-- 合作begin -->
<div class="cor" style="margin-top:100px;" >
    <h6>项目合作信息</h6>
    <div class="process">
        <img src="/images/logo/pro2.png" alt="" />
    </div>

    <div class="cor content-form-box" id="step2Form"    >

        <form class="step2" method="post"     >
            <input type="hidden" value="{#$smarty.get.id #}" id="resId"  />
            <input type="reset" name="reset" class="reset" style="display: none;" />
            <ul class="product"> 
                <li id="productCategory">
                    <div><i>*</i><span>选择产品分类：</span></div>
                        <div class="check-list product-category-radios">
                            <label>
                                <input type="radio" name="productCategory" value="1" class="tianhua category-radio"   />
                                <span>天花</span>
                            </label>
                            <label>
                                <input type="radio" name="productCategory" value="2" class="qiangban category-radio"  />
                                <span>墙板</span>
                            </label>
                            <label>
                                <input type="radio" name="productCategory" value="3"  class="dengju category-radio"  />
                                <span>灯具</span>
                            </label>

                            <label>
                                <input type="radio" name="productCategory" value="4" class="fengkou category-radio" />
                                <span>风口</span>
                            </label>
                            <label>
                                <input type="radio" name="productCategory" value="5" class="tijiaoxian category-radio"  />
                                <span>踢脚线</span>
                            </label>
                            <label>
                                <input type="radio" name="productCategory" value="6" class="chuanglian category-radio"  />
                                <span>窗帘 </span>
                            </label>

                        </div>

                </li>



                <li class="raw typeSecond "   id="typeSecond"  >  </li>

                <li class="raw typeThird "   id="typeThird"  >  </li>

            </ul>

            <div style="margin-left:300px; margin-top:15px;" >
                <div style="float: left">
                    <button class="btn save"  id="save" type="button"   name="save" value="0" style="background: #009C4C;color: #fff;"  onclick="saveform(this)"   >保存 </button>
                </div>

                <div style="float: left;margin-left:110px;">
                    <button class="btn del" id="del" type="button" name="del" value="0"  onclick="dell(this)"    > 删除 </button>
                </div>
            </div>

        
    </div>

</div>
<!-- 合作over -->

<div class="aa"></div>

<div class="count">
    <button class="btn addProduct"  type="button"   onclick="addProduct()" style="background: #337ab7;">+添加产品  </button>
</div>

<div class="bg"></div>

<!-- 统计begin -->
<div class="count">
    <div id="count-view-box" ></div>
    
    <button class="btn" type="button" name="step2"  value="2"  onclick="checkStep()">下一步</button>

</div>
<!-- 统计over -->

</form>








<!-- 咨询栏begin -->
{# include file="$tpl_root_path/front/public/_contact.html" #}

<!-- 咨询栏over -->



<!-- 底部begin -->
{# include file="$tpl_root_path/front/public/_footer.html" #}
<!-- 底部over -->



</body>
</html>


<script type="text/javascript">

        var arrPubTypes = 		[
		 {'name':'天花','types':'1,2,3','isShowWhichType':1,'isShowProductType':true,'isShowNum':0,'isShowSize':false},
		 {'name':'墙板','types':'1,2,3','isShowWhichType':1,'isShowProductType':true,'isShowNum':0,'isShowSize':false},
		 {'name':'灯具','types':'1,2,3','isShowWhichType':2,'isShowProductType':true,'isShowNum':3,'isShowSize':false},
		 {'name':'风口','types':'1,2,3','isShowWhichType':3,'isShowProductType':false,'isShowNum':4,'isShowSize':true},
		 {'name':'踢脚线','types':'1,2','isShowWhichType':1,'isShowProductType':false,'isShowNum':5,'isShowSize':false},
		 {'name':'窗帘','types':'1,4,5,6,7','isShowWhichType':1,'isShowProductType':false,'isShowNum':6,'isShowSize':false},
		];
		
 
		var $inputTupes =  $(".category-radio");
		
		$inputTupes.each(function(i, e) {
			var $types = arrPubTypes[i];
            $(this).bind('click',function(){
				showTypeSecond($types['types'],$types['isShowWhichType'],$types['isShowProductType'],$types['isShowNum'],$types['isShowSize'],$(this));
			});
        });
		
   

//筛选材料显示的类型
    var arrPublicType = ['','铝合金','不锈钢','镀锌钢板','太阳布','柔纱','竹板','木板'];

    function showTypeSecond(types,isShowWhichType,isShowProductType,isShowNum,isShowSize,$self){

        isShowWhichType=isShowWhichType?isShowWhichType:false;
        isShowProductType=isShowProductType?isShowProductType:false;
        isShowNum=isShowNum?isShowNum:false;
        isShowSize=isShowSize?isShowSize:false;

        var arrTypes = types.split(',');
        var paramsTypes = [];
        var strParamsType = '';
        if(arrTypes.length == 0){
            return false;
        }
        for(var i=0;i<arrTypes.length;i++){
            var tid = arrTypes[i];
            if(arrPublicType[tid]){
                paramsTypes.push(arrPublicType[tid]);
            }
        }

        strParamsType = paramsTypes.join(',');
//        alert(strParamsType);

        if(isShowWhichType=='1'){//显示材料类型
            isShowWhichType='1';
        }else if(isShowWhichType=='2'){//显示灯具类型
            isShowWhichType='2';
        }else if(isShowWhichType=='3'){//显示风口类型
            isShowWhichType='3';
        }



        if(isShowProductType){
            isShowProductType='1';
        }else {
            isShowProductType='0';
        }

        if(isShowNum=='1'){//天花数量
            isShowNum='1';
        }else if(isShowNum=='2') {//墙板数量
            isShowNum='2';
        }else if(isShowNum=='3') {//灯具数量
            isShowNum='3';
        }else if(isShowNum=='4') {//风口数量
            isShowNum='4';
        }else if(isShowNum=='5') {//踢脚线数量
            isShowNum='5';
        }else if(isShowNum=='6') {//窗帘数量
            isShowNum='6';
        }else {
            isShowNum=='0'
        }

        if(isShowSize){
            isShowSize='1';
        }else {
            isShowSize='0';
        }


        var level = 0;
        if($self.data('level')){
            level = $self.data('level');
        }

        if(level > 0){
            var $form = $("#step2Form"+level );
        }else{
            var $form = $("#step2Form");
        }
        var sortVal = $form.find('.category-radio:checked').val();  //用户选中的产品分类值
//        alert(sortVal);

        var materialType=$form.find('.materialList:checked').val();//用户选择的材料类型值

//alert($self.data('level'))
//        alert(typeof isShowProductType);


        if(level > 0){
            var $selftypeThird = $("#typeThird"+level );
        }else{
            var $selftypeThird = $("#typeThird");
        }
        $selftypeThird.css('display','none');

        if(strParamsType!=''){
            $.get("/cooperate/index.html", {
                'cmd':'show',
                'list':strParamsType,
                'isShowWhichType':isShowWhichType,
                'isShowProductType':isShowProductType,
                'isShowNum':isShowNum,
                'isShowSize':isShowSize,
                'sortVal':sortVal,
                'materialType':materialType,

            },function( data ) {
                if(data){
					
					if(level > 0){
					  var $self = $("#typeSecond"+level );  
					}else{
					  var $self = $("#typeSecond");  
					}
					
					$self.html(data);
					
					//输入框blur
//					$self.find('.count-num').blur(function(){
//					    countProductSum(level,$self);
//					});
					
				   
				 }
            });
        }




    }











//添加产品
    function addProduct(){
//        $(".aa").append(  $('#step2Form').clone(true));
        var length=$('.save').length;

        if(length>=30){
            alert('最多可添加30个产品');
           return false;
        }


        var jj =   $( ".content-form-box");
        var jjl = jj.length;

//		 alert(length)
        var lastResid = 0;
        if($('#step2Form'+length).data('resId')){
            lastResid = $('#step2Form'+length).data('resId');
        }

        $('#step2Form'+length).data('resId','')


//        alert(length);
         $("#step2Form").clone(true).attr("id",'step2Form'+length).insertBefore($(".aa"));


        //修改#step2Form的id值
        $('#step2Form'+length).data('resId',lastResid)



        for (var i=1; i<jj.length; i++){
            jj[i].setAttribute('id',"step2Form"+i);
            $(jj[i]).data('level',i);
//            $(jj[i]).data('resId','');
        }


        //修改typeSecond的id值

        var bb =   $( ".typeSecond");
        for (var i=1; i<bb.length; i++){
            bb[i].setAttribute('id',"typeSecond"+i);
            bb[i].setAttribute('value',i);
			$(bb[i]).data('level',i);
        }


//修改天花的name值
        var aa =   $( ".tianhua");
        for (var i=1; i<aa.length; i++){
            aa[i].setAttribute('id',"tianhua"+i);
			$(aa[i]).data('level',i);
        }


//修改墙板的name值
        var cc =   $( ".qiangban");
        for (var i=1; i<cc.length; i++){
            cc[i].setAttribute('id',"qiangban"+i);
            $(cc[i]).data('level',i);
        }


//修改灯具的name值
        var dd =   $( ".dengju");
        for (var i=1; i<dd.length; i++){
            dd[i].setAttribute('id',"dengju"+i);
            $(dd[i]).data('level',i);
        }


//修改风口的name值
        var ee =   $( ".fengkou");
        for (var i=1; i<ee.length; i++){
            ee[i].setAttribute('id',"fengkou"+i);
            $(ee[i]).data('level',i);
        }


//修改踢脚线的name值
        var ff =   $( ".tijiaoxian");
        for (var i=1; i<ff.length; i++){
            ff[i].setAttribute('id',"tijiaoxian"+i);
            $(ff[i]).data('level',i);
        }


//修改窗帘的name值
        var gg =   $( ".chuanglian");
        for (var i=1; i<gg.length; i++){
            gg[i].setAttribute('id',"chuanglian"+i);
            $(gg[i]).data('level',i);
        }



//修改“保存”的name值
    var hh =   $( ".save");
    for (var i=1; i<hh.length; i++){
        hh[i].setAttribute('id',"save"+i);
        hh[i].setAttribute('name',"save"+i);
        hh[i].setAttribute('value',i);
        $(hh[i]).data('level',i);
    }


//修改“删除”的name值
        var kk =   $( ".del");
        for (var i=1; i<kk.length; i++){
            kk[i].setAttribute('id',"del"+i);
            kk[i].setAttribute('name',"del"+i);
            kk[i].setAttribute('value',i);
            $(kk[i]).data('level',i);
        }



        var nn =   $( ".typeThird");
        for (var i=1; i<nn.length; i++){
            nn[i].setAttribute('id',"typeThird"+i);
            nn[i].setAttribute('name',"typeThird"+i);
            nn[i].setAttribute('value',i);
            $(nn[i]).data('level',i);
        }


    }




        // 点击材料类型
        function showClickMaterial(obj){

            var $obj=$(obj);
            var $typeSecond=$obj.parent().parent().parent();
            var value=$typeSecond.attr('value');
//            console.log(value)

            if(value>0){
                var $categoryBox = $('#step2Form'+value);
            }else{
                var $categoryBox = $('#step2Form');
            }





            var sortVal = $categoryBox.find('.category-radio:checked').val();  //用户选中的产品分类值
            if(sortVal==1||sortVal==2){//天花及墙板下 点击材料类型
                if(value > 0){
                    var $selftypeThird = $("#typeThird"+value );
                }else{
                    var $selftypeThird = $("#typeThird");
                }
                $selftypeThird.css('display','block');
                var materialListVal=   $categoryBox.find('.materialList:checked').val(); //用户选中的材料类型值
                $.get("/cooperate/index.html", {'cmd':'showClickMaterial','sortVal':sortVal, 'materialListVal':materialListVal,  },function( data ) {
                    if(data){

                        if(value > 0){
                            var $self = $("#typeThird"+value );
                        }else{
                            var $self = $("#typeThird");
                        }
                        $self.html(data);
                    }
                });
            }

        }










function countProductSum(level,$self){
  var arrCategory  = [
     {'name':'其他','unit':'㎡','sum':0},
	 {'name':'天花','unit':'㎡','sum':0},
	 {'name':'墙板','unit':'㎡','sum':0},
	 {'name':'灯具','unit':'个','sum':0},
	 {'name':'风口','unit':'个','sum':0},
	 {'name':'踢脚线','unit':'m','sum':0},
	 {'name':'窗帘','unit':'㎡','sum':0},
	]
	//计算统计值
	var $forms = $('.content-form-box');
	
	$forms.each(function(index, element) {
        var $this = $(this);
		
		var $category = $this.find('.product-category-radios');
		if($category.length > 0){
		    var sortVal = $category.find('.category-radio:checked').val();  //用户选中的产品分类值
	    }
	    //用户输入的产品数量值
        var $num= $this.find('.count-num');
        var numVal = $num.val();
		
		if(sortVal && numVal){
			arrCategory = countProductType(sortVal,numVal,arrCategory);
		}
		
    });//end each

   //输出结果
   var $countView = $('#count-view-box');
   var clen = arrCategory.length;
   var shtml = '<p>统计:</p>';
   shtml += '<table  border="0" cellspacing="1" cellpadding="0" >';
   for(var i=0;i<clen;i++){
	   if(i>0){
		 var $oCate = arrCategory[i];	
		 shtml += '<tr>';
		 shtml += '<td>'+$oCate['name']+'</td>';
		 shtml += ' <td>'+$oCate['sum']+$oCate['unit']+'</td>';
		 shtml += ' </tr>  ';
	   }
   }//end for
   shtml += '</table>';
   
   $countView.empty();
   $countView.html(shtml);
   
//   console.log(arrCategory)
   

}

function countProductType(sortVal,numVal,arrCategory){
	if(!sortVal || !numVal){
		return false;
	}
	var clen = arrCategory.length;
	if(clen > 0){
		  for(var i=0;i<clen;i++){
			  var $oCate = arrCategory[i];
			  if(sortVal==i){
//				 console.log(i+'=='+numVal);
				 var sum = $oCate['sum'];
				 sum = parseInt(numVal) + parseInt(sum);
				 $oCate['sum'] = sum;
			  }
		  }//end for
	   
	 return arrCategory;	
	}
}


//保存
    function saveform(obj){

        var name=obj.name;
        var value=obj.value;
        var id= $('#resId').val();
		var resId = 0;
		
		if(value>0){
		    var $categoryBox = $('#step2Form'+value);
		}else{
			var $categoryBox = $('#step2Form');
		}


//表单验证

        //验证产品分类
        var productCategory = '';
        $categoryBox.find('.product-category-radios input').each(function(){
            if($(this).prop("checked")){
                productCategory = $(this).val();
            }
        });
        if(productCategory==''){
            alert('请选择产品分类');
            return false;
        }


    //验证材料、灯具类型
        var materialList='';
        $categoryBox.find('.typeSecond input').each(function(){
            if($(this).prop("checked")){
                materialList = $(this).val();
            }
        });
        if(materialList==''){
            alert('请选择类型');
            return false;
        }

       var productCategoryC = $categoryBox.find('.category-radio:checked').val();//用户选择的产品分类值

//验证风口类型
        if( productCategoryC==4  ){
            var tuyereType='';
            $categoryBox.find('.tuyereType').each(function(){
                if($(this).prop("checked")){
                    tuyereType = $(this).val();
                }
            });
            if(tuyereType==''){
                alert('请选择风口类型');
                return false;
            }
        }

//验证产品、材料类型
        if( productCategoryC==1 ||productCategoryC==2 ||productCategoryC==3   ){

            var productType= $categoryBox.find('.productTypeSelect').val();
            if(productType==0){
                alert('请选择产品/材料类型');
                return false;
            }

        }



    //验证数量
        var num= $categoryBox.find('.count-num').val();
        var re =  /^\d{1,9}?$/ ;
        if(!re.test(num)|| num==0){
            alert('请输入数量,必须为9位数内的正整数');
            return false;
        }


        //验证尺寸
//        if( $categoryBox.find('#size input')){
//            var size='';
//            $categoryBox.find('#size input').each(function(){
//                if($(this).prop("checked")){
//                    size = $(this).val();
//                }
//            });
//            if(size==''){
//                alert('请选择尺寸');
//                return false;
//            }
//        }






		
		resId = $categoryBox.data('resId');

//        console.log(obj);
//        console.log(resId);

		var productCategory = '';
		var materialType='';
		var luminaireType='';
		var tuyereType='';
		var productType='';
		var num='';
		var size='';

		productCategory = $categoryBox.find('.category-radio:checked').val();//用户选择的产品分类值

        materialType=$categoryBox.find('.materialList:checked').val();//用户选择的材料类型值

        luminaireType=$categoryBox.find('.luminaireType:checked').val();//用户选择的灯具类型值

        tuyereType=$categoryBox.find('.tuyereType:checked').val();//用户选择的风口类型值

         productType=$categoryBox.find('.productTypeSelect option:selected').val();   //用户选择的产品类型

        num=$categoryBox.find('.count-num').val();//用户输入的数量

        size=$categoryBox.find('.size:checked').val();//用户选中的尺寸

		$.get("/cooperate/index.html", 
		   {'cmd':'save',
		    'name':name,
			'id':id,
			'resId':resId,
			'value':value,
			'productCategory':productCategory,
            'materialType':materialType,
			'luminaireType':luminaireType,
			'tuyereType':tuyereType,
			'productType':productType,
			'num':num,
			'size':size
			},
			function( data ) {
			  if (data == 0) {
				  alert("保存失败!")
			  }else {
				  $categoryBox.data('resId',data)
				  alert("保存成功!")
//                  $categoryBox.find('.save').text('修改');

                  //统计
                 
				 
                  if(value > 0){
                      var $self = $("#typeSecond"+value );
                  }else{
                      var $self = $("#typeSecond");
                  }

                  if(value && $self){
                     countProductSum(value,$self);
				  }



			  }
            }
		);





    }


        //删除
        function dell(obj){
			var name=obj.name;
			var value=obj.value;
			var id= $('#resId').val();//url的id参数值
			var resId = 0;
					
			if(value>0){
				var $categoryBox = $('#step2Form'+value);
			}else{
				var $categoryBox = $('#step2Form');
			}
			
			resId = $categoryBox.data('resId');

            $.get("/cooperate/index.html",
                    {'cmd':'del',
                        'name':name,
                        'id':id,
                        'resId':resId,
                        'value':value,
                    },
                    function( data ) {
                        if (data == 1) {
                            alert("删除成功!")
//                            $categoryBox.css('display','none');
                            $categoryBox.find('.reset').trigger("click");//清空当前表单内容
							$categoryBox.data('resId','')

                            //统计


                            if(value > 0){
                                var $self = $("#typeSecond"+value );
                            }else{
                                var $self = $("#typeSecond");
                            }

                            if(value && $self){
                                countProductSum(value,$self);
                            }


                        }else if(data == 0){
                            alert("删除失败!")
                        }else {

                            alert("删除失败!")

                        }
                    }
            );
        }


        function checkStep(){
            var id= $('#resId').val();
            $.get("/cooperate/index.html", {'cmd':'checkStep','id':id},function( data ) {
                if(data==0){
                    alert('请先保存')
                    return false;
                }else {
                    window.location.href='http://www.gzcanr.com/cooperate/index-cmd-step3-id-'+id+'.html'
                }
            });


        }


</script>